<template>
  <div class="org-manage-index sub-margin">
    <!-- <div class="sub-page-title">考核模板</div> -->
    <div class="content" v-if="!isLoading">
      <Empty v-if="showEmpty" @create="addCheckModule"></Empty>
      <template v-if="!showEmpty">
        <MouldTable
          :source="tableData"
          @add-scheme="addCheckModule"
          @search-list="searchData"
          @edit-scheme="editModule"
          @launch-scheme="launchScheme"
          @del-scheme="delModule"
          @view-scheme="viewModule"
          @copy-scheme="copyModule">
          <pagination
            slot="pagination"
            :page-size.sync="pageParam.pageSize"
            :total="pageParam.totalSize"
            :current-page.sync="pageParam.currentPage"
            :pageSizes="[10, 20]"
            layout="slot,prev, pager, next, sizes, jumper"
            @change="onPageChange"></pagination>
        </MouldTable>
      </template>
    </div>
    <div class="content" v-if="isLoading">
      <!-- <Loading :isLoading="isLoading"></Loading> -->
    </div>
  </div>
</template>

<script>
import Empty from './components/Empty.vue'
import MouldTable from './components/MouldTable.vue'
import pagination from '@com/pagination'

import { queryAssessTemplateList, delAssessTemplate, copyTemplate } from '@api/modules/assessModule.js'

export default {
  name: 'OrgManageIndex',
  components: { MouldTable, pagination, Empty },
  data() {
    return {
      showTypeDialog: false,
      curOrgType: {},
      tableData: [],
      showOrgDialog: false,
      dialogType: 'add',
      curOrg: {},
      pageParam: {
        currentPage: 1,
        pageSize: 10,
        totalSize: 0,
      },
      searchList: false,
      isLoading: false,
      keywords: '',
    }
  },
  computed: {
    showEmpty() {
      // return true
      return !this.searchList && this.tableData.length === 0
    },
  },
  created() {
    this.isLoading = true
    this.searchList = false
    this.initData()
  },
  methods: {
    async initData(type) {
      this.curOrg = {}
      const params = {
        keywords: this.keywords,
        status: '',
        tenantId: '',
      }
      const { status, data } = await queryAssessTemplateList(
        params,
        this.pageParam.currentPage,
        this.pageParam.pageSize
      )
      this.isLoading = false
      if (status === 200 && data.content && data.content.length) {
        this.tableData = data.content
        this.pageParam.totalSize = data.totalSize
      } else {
        this.tableData = []
      }
    },
    addCheckModule() {
      this.$router.push({
        name: 'JXGL_MOULD_MANAGE_ADDEDIT',
        query: {
          id: '',
        },
      })
    },
    searchData(data) {
      this.keywords = data.title || ''
      this.searchList = true
      this.pageParam.currentPage = 1
      this.initData()
    },
    editModule(data) {
      this.$router.push({
        name: 'JXGL_MOULD_MANAGE_ADDEDIT',
        query: {
          id: data.id,
        },
      })
    },
    launchScheme() {},
    async delModule(obj) {
      const { status } = await delAssessTemplate(obj.id)
      if (status === 200) {
        this.$message.success('删除成功')
        this.pageParam.currentPage = 1
        this.pageParam.pageSize = 10
        this.initData()
      }
    },
    onPageChange(obj) {
      this.pageParam.currentPage = obj.pageNumber
      this.pageParam.pageSize = obj.pageSize
      this.initData()
    },
    viewModule(data) {
      this.$router.push({
        name: 'JXGL_MOULD_MANAGE_ADDEDIT',
        query: {
          id: data.id,
          type: 'view',
        },
      })
    },
    copyModule(data) {
      copyTemplate(data.id).then(res => {
        if (res.status === 200) {
          this.$message.success('复制创建成功')
          this.pageParam.currentPage = 1
          this.initData()
        }
      })
    },
  },
}
</script>
<style lang="scss" scoped>
@import '@styles/layout.scss';

.org-manage-index {
  display: flex;
  flex-direction: column;
  height: 100%;

  .content {
    flex: 1;
    padding: 20px 0;
    height: calc(100vh - 110px);
  }
}
</style>
